from utils import define_print

FUNC_REGISTERS = {
    'BN_MONT_EXP': 0x01,

    'DOUBLE_POINT': 0x11,
    'POINT_ADD': 0x12,
    'POINT_MUL': 0x13,
    'JAC_TO_AFF': 0x14,

    'TEST_FUNC': 0xff
}

# name: id (type)
INST_REGISTERS = {
    'END': 0x00,
    'NOP': 0x01,

    'RET': 0x04,
    'CALL': 0x05,
    'JMP': 0x06,
    'JZ': 0x07,
    'JE': 0x08,
    'JA': 0x09,
    'JB': 0x0a,
    'JG': 0x0b,
    'JL': 0x0c,

    'ADD': 0x10,
    'ADDI': 0x11,
    'SUB': 0x12,
    'SUBI': 0x13,

    'MEM_SET': 0x19,
    'MEM_COPY': 0x1a,
    'JP_JNE': 0x1b,

    'BN_LOAD': 0x20,
    'BN_STORE': 0x21,
    'BN_ADD': 0x22,
    'BN_SUB': 0x23,

    'BN_LOAD_MOD': 0x25,
    'BN_MOD_ADD': 0x26,
    'BN_MOD_SUB': 0x27,
    'BN_MONT_MUL': 0x28,
    'BN_MOD_INV': 0x29,

    'BN_JZ': 0x2b,
    'BN_JE': 0x2c,
    'BN_JA': 0x2d,
    'BN_JB': 0x2e,
    'BN_JZ_BIT': 0x2f,
}


def get_function_id_by_name(name):
    return FUNC_REGISTERS[name]


def gen_registers():
    for inst, ID in INST_REGISTERS.items():
        define_print(f'INST_{inst}', f'8\'h{ID:02x}')
    print()
    for inst, ID in FUNC_REGISTERS.items():
        if ID < 128:
            define_print(f'FUNC_{inst}_ID', f'8\'h{ID:02x}')
        else:
            define_print(f'ALGO_{inst}_ID', f'8\'h{ID:02x}')


if __name__ == '__main__':
    gen_registers()